package com.shopping.www.controller;

import com.alibaba.fastjson.JSONObject;
import com.shopping.www.model.MenuList;
import com.shopping.www.service.MenuService;

import javax.servlet.*;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

@WebServlet("/menu/*")
public class MenuServlet extends BaseServlet {
    private MenuService service1=new MenuService();
    public void showMenu(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        List<MenuList> menuList=service1.showMenu();
        response.setContentType("text/json;charset=utf-8");
        PrintWriter printWriter=response.getWriter();
        JSONObject jsonArray=new JSONObject();
        jsonArray.put("menuList",menuList);
        printWriter.print(jsonArray);
    }
    public void showMenuChildren(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
        List<MenuList> menuChildrenList=service1.showMenuChildren();
        response.setContentType("text/json;charset=utf-8");
        PrintWriter printWriter=response.getWriter();
        JSONObject jsonArray=new JSONObject();
        jsonArray.put("menuChildrenList",menuChildrenList);
        printWriter.print(jsonArray);
    }
}
